package com.xgp.javateacher;

import org.junit.Test;

import java.util.Scanner;

/**
 * java课第一次作业
 */
public class Demo1 {
    /**
     *
     *   进制转换
     */
    @Test
    public void test1() {
        long input = 0;
        String num2 = null;
        String num8 = null;
        String num10 = null;
        String num16 = null;

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要转换的数字：");
        String str = scanner.nextLine();
        System.out.println("该数字的进制为（2，10，8，16）：");
        int num = scanner.nextInt();
        if(!str.isEmpty()) {
            switch (num) {
                case 2:input = Long.parseLong(str, num);break;
                case 8:input = Long.parseLong(str, num);break;
                case 10:input = Long.parseLong(str, num);break;
                case 16:input = Long.parseLong(str, num);break;
            }
            num2 = Long.toBinaryString(input);
            num8 = Long.toOctalString(input);
            num10 = Long.toString(input);
            num16 = Long.toHexString(input);

            System.out.println(num2);
            System.out.println(num8);
            System.out.println(num10);
            System.out.println(num16);

//            System.exit(0);
        }
    }


/*    @Test
    public void test2() {
        int


    }*/
}
